package com.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.ConnectionBean;
import com.project.service.IConnectionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiresPermissions("connection")
@RequestMapping("connection")
public class ConnectionController {
    @Autowired
    private IConnectionService connectionService;

    @RequestMapping("findByItem")//根据输入的客户名称，经营的范围动态查询，返回客户分页对象
    public IPage<ConnectionBean> findByItem(Integer pageNO, String name, String scope) {
        return connectionService.findByItem(pageNO, name, scope);
    }
    @RequestMapping("findById")
    public ConnectionBean findById(Integer id) {//根据id查询客户信息
        return connectionService.findById(id);
    }
    @RequestMapping("updateInfo")
    public String updateInfo(Integer id, String director, String phone, String scope) {
        //根据客户id 修改 客户负责人名字和 电话号码，经营范围
        connectionService.updateInfo(id, director, phone, scope);
        return "ok";
    }
    @RequestMapping("add")
    public String add(ConnectionBean connectionBean) {
        //添加客户，如果客户名称相同，则不做添加
        boolean flag = connectionService.add(connectionBean);
        if (flag != false) {
            return "ok";
        }
        return "no";
    }
    @RequestMapping("findAll")
    public List<ConnectionBean> findAll() {
        //查询所有客户
        return connectionService.findAll();
    }
}
